package com.liao.intimacy;

import com.liao.kv.key.ComDimension;
import com.liao.kv.value.CountDurationValue;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
                        //输入是<13129799790_18811821248 180>
public class RankReducer extends Reducer<Text, Text,Text, CountDurationValue> {
    //133_144   158
    private CountDurationValue v=new CountDurationValue();

    @Override  ///133_144   158
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //通话次数
        int countSum=0;//一个key进来就重新初始化为0
        //通话时长
        int sumDuration = 0;


        for(Text value : values){
            countSum ++;
            sumDuration += Integer.valueOf(value.toString());//转整形
        }

        v.setCallSum(countSum);//设置次数
        v.setCallDurationSum(sumDuration);//时长

        context.write(key,v);
    }
}
